package group.sicher.core.web.parse;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.springframework.util.ObjectUtils;

import java.io.IOException;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * Created by bootvue@gmail.com
 * Date 2019-04-07 14:25
 *
 * HH:mm:ss
 */
public class TimeSerialize extends JsonSerializer<Long> {
    @Override
    public void serialize(Long value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (ObjectUtils.isEmpty(value)) {
            gen.writeNull();
        } else {
            gen.writeString(new Date(value).toInstant().atZone(ZoneOffset.of("+8")).toLocalDateTime().format(DateTimeFormatter.ofPattern("HH:mm:ss")));
        }
    }
}
